﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Timers;
using System.Windows;
using System.Windows.Threading;
using Jungle_Timers.Entities;

namespace Jungle_Timers.Helpers
{
    public class TimerManager : ObservableCollection<ITimedItem>
    {
        private Timer gameTimer;
        private TimeSpan totalTime;
        
        public TimerManager()
        {
            gameTimer = new Timer(10);
            gameTimer.AutoReset = true;
            gameTimer.Elapsed += new ElapsedEventHandler(gameTimer_Elapsed);
            gameTimer.Start();
        }

        void gameTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
    
            for (int index = 0; index < this.Count; index++)
            {
                ITimedItem item = this[index];
                if (item.ElapsedTime.TotalSeconds > item.CoolDown.TotalSeconds)
                {
                   continue;
                }

                item.ElapsedTime = DateTime.Now.Subtract(item.StartTime);

            }
        }
    }


}
